package mytest;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;


public class Test_24dian {

	static String express ;
	
	static int arr[]={2,1,1,48};
	
	static boolean v[]=new boolean[4];
	static int count;
	static void solve(double cur,int k)
	{
		count++;
		if(k==4)
		{
			if(Math.abs(cur-24)<1e-7){
				System.out.println(express);
			}
			return;
		}
		for(int i=0;i<4;i++)
		{
			if(k>0)
			{
				if(v[i]==false){
					v[i]=true;
					double tmp=cur*arr[i];
					String hs=express;
					express="("+hs+"*"+arr[i]+")";
					solve(tmp,k+1);
					tmp=cur-arr[i];
					express="("+hs+"-"+arr[i]+")";
					solve(tmp, k+1);
					tmp=arr[i]-cur;
					express="("+arr[i]+"-"+hs+")";
					solve(tmp, k+1);
					tmp=cur+arr[i];
					express="("+arr[i]+"+"+hs+")";
					solve(tmp, k+1);
					if(arr[i]!=0)
					{
						tmp=cur/arr[i];
						express="("+hs+"/"+arr[i]+")";
						solve(tmp, k+1);
					}
					if(cur!=0)
					{
						tmp=arr[i]/cur;
						express="("+arr[i]+"/"+hs+")";
						solve(tmp, k+1);
					}
					v[i]=false;
					express=hs;
				}
			}else{
				if(v[i]==false)
				{
					v[i]=true;
					String hs=express;
					express=String.valueOf(arr[i]);
					solve(arr[i], k+1);
					express=hs;
					v[i]=false;
				}
			}
		}
	}
	
	
	static class Node{
		String express;
		double value;
		@Override
		public int hashCode() {
			// TODO Auto-generated method stub
			return (int)value;
		}
		@Override
		public boolean equals(Object obj) {
			// TODO Auto-generated method stub
			Node n=(Node)obj;
			if(Math.abs(this.value-n.value)<1e-7)
			{
				return true;
			}
			return false;
		}
	}
	
	
	static void solve2()
	{
		for(int i=0;i<4;i++)
		{
			Set<Node> set=new HashSet<Node>();
			Node n=new Node();
			n.express=String.valueOf(arr[i]);
			n.value=arr[i];
			set.add(n);
			Sarr[1<<i]=set;
		}
		
		for(int i=1;i<16;i++)
		{
			Sarr[i]=f(i);
		}
		
		for(Iterator<Node> it=Sarr[15].iterator();it.hasNext();)
		{
			Node n=it.next();
			if(Math.abs(n.value-24)<1e-7)
			{
				System.out.println(n.express);
			}
		}
	}
	
	static Set<Node> [] Sarr=new Set[16];
	
	static Set<Node> fork(Set<Node> set1,Set<Node> set2)
	{
		Set<Node> set=new HashSet<Node>();
		Object[] a1=set1.toArray();
		Object[] a2=set2.toArray();
		for(int i=0;i<a1.length;i++)
			for(int j=0;j<a2.length;j++)
			{
				Node n1=(Node)a1[i];
				Node n2=(Node)a2[j];
				Node n3=new Node();
				n3.value=n1.value+n2.value;
				n3.express="("+n1.express+"+"+n2.express+")";
				set.add(n3);
				n3=new Node();
				n3.value=n1.value-n2.value;
				n3.express="("+n1.express+"-"+n2.express+")";
				set.add(n3);
				n3=new Node();
				n3.value=n2.value-n1.value;
				n3.express="("+n2.express+"-"+n1.express+")";
				set.add(n3);
				n3=new Node();
				n3.value=n1.value*n2.value;
				n3.express="("+n1.express+"*"+n2.express+")";
				set.add(n3);
				if(Math.abs(n1.value)>1e-7)
				{
					n3=new Node();
					n3.value=n2.value/n1.value;
					n3.express="("+n2.express+"/"+n1.express+")";
					set.add(n3);
				}
				if(Math.abs(n2.value)>1e-7)
				{
					n3=new Node();
					n3.value=n1.value/n2.value;
					n3.express="("+n1.express+"/"+n2.express+")";
					set.add(n3);
				}
			}
		return set;
	}
	
	static Set<Node> f(int i)
	{
		if(Sarr[i]!=null)return Sarr[i];
		count++;
		Sarr[i]=new HashSet<Node>();
		for(int x=1;x<i;x++)
		{
			if((x&i)==x)
			{
				//Set<Node> s1=f(x);
				//Set<Node> s2=f(i-x);
				//Set<Node> s3=fork(s1,s2);
				Sarr[i].addAll(fork(f(x),f(i-x)));
			}
		}
		
		return Sarr[i];
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		//solve(0, 0);
		solve2();
		System.out.println(count);
	}

}
